#!/bin/sh

# centos 搭建nodejs + mysql运行环境
# 基于aliyun的Centos7.0-64 操作系统
# 1.修改ssh端口  user密码  
# 2.在线安装需要库文件,更新系统
# 3.加入开机运行并构建服务器
echo "1.修改root用户名的密码"
passwd root
echo "2.修改ssh的远程访问端口"
git config --global user.name "GeanlinZh"
git config --global user.email geanlinzh@163.com

vi /etc/ssh/sshd_config
service sshd restart
echo "3.更新操作系统"
yum update -y
echo "4.安装系统需要的库"
yum install gcc gcc-c++ mariadb mariadb-server git-all -y
echo "5.安装nodejs库"

cd /home
mkdir aliyun
cd aliyun
version=v12.13.0
if [ ! -f "/usr/bin/node" ]
then
    wget http://nodejs.org/dist/$version/node-$version-linux-x64.tar.gz 
	tar -zxvf node-$version-linux-x64.tar.gz 
	cd node-$version-linux-x64
	rm C* L* R*
	cp -rf ./* /usr/
	cd ..
fi  
pwd
rm -rf ./*
echo "6.安装node-gyp"
if [ ! -f "/usr/bin/node-gyp" ]
then
	npm install node-gyp -gd
fi  
echo "7.安装forever"
if [ ! -f "/usr/bin/forever" ]
then
	npm install forever -gd
fi 
echo "8.获取aliyum-node源码"
if [ -d "/home/Geanlin/aliyun-node" ]
then
	rm -rf aliyun-node
fi 
git clone https://git.oschina.net/geanlinzh/aliyun-node.git
cd aliyun-node
npm install
echo "9.设置nodejs服务"
cd ..
git clone https://git.oschina.net/geanlinzh/shell-app.git
cd shell-app
cp nodejs  /etc/init.d/
cd ..
rm -rf  shell-app
echo "10.设置开机启动服务"
chkconfig --add nodejs
chkconfig nodejs on
chkconfig enable mariadb
chkconfig --add mariadb
chkconfig mariadb on
reboot
